package com.hdy.demo.tag.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.hdy.demo.tag.entity.Groups;
import com.hdy.demo.tag.service.PagingService;
import com.hdy.framework.struts2.action.BaseAction;
import com.hdy.framework.tag.paging.IPaging;
import com.hdy.framework.tag.paging.utils.PagingInfoUtils;

/**
 * hdy
 * 2013-4-15下午8:58:33
 * http://127.0.0.1:8080/ssh/tag/groupsPaging.action
 */
@Scope("prototype")
@Component("groupsPagingAopAction")
public class GroupsPagingAopAction extends BaseAction implements IPaging{
	private static final long serialVersionUID = 1L;
	@Resource(name="pagingServiceAop")//放在属性可以省略get set方法 也可以放在set方法前面
	private PagingService pagingServiceAop;
	private Date startTime;
	private Date endTime;
	private String name;
	private List<Groups> ls;
	@Override
	public String execute() {
		return SUCCESS;
	}


	@Override
	public Map<String, Object> getQueryMap() {
		setParam();
		Map<String,Object> queryMap = new HashMap<String,Object>();
		if(StringUtils.isNotBlank(name)){
			queryMap.put("name", name);
		}
		if(startTime==null){
//			startTime = new Date();
		}
		queryMap.put("startTime", startTime);
		if(endTime==null){
			endTime=new Date();
		}
		queryMap.put("endTime", endTime);
		return queryMap;
	}
	private void setParam(){
		String pagingInfo = this.getPagingInfo();
		String nameInfo = PagingInfoUtils.get().getString("name", pagingInfo);
		if(StringUtils.isNotBlank(nameInfo)){
			this.name=nameInfo;
		}
		Date startDateInfo = PagingInfoUtils.get().getDate("startTime", pagingInfo);
		if(startDateInfo!=null){
			this.startTime=startDateInfo;
		}
		Date endDateInfo = PagingInfoUtils.get().getDate("endTime", pagingInfo);
		if(endDateInfo!=null){
			this.endTime=endDateInfo;
		}
	}
	@SuppressWarnings("unchecked")
	@Override
	public <T> void setPageList(List<T> ls) {
		this.ls=(List<Groups>) ls;
	}
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public List<Groups> getLs() {
		return ls;
	}

	public void setLs(List<Groups> ls) {
		this.ls = ls;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

}
